Completed
Pull Request — master (#120)
by Maxence
03:22
created

Circles.initialize   B

Complexity

Conditions 1
Paths 2

Size

Total Lines 33

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 1 Features 0
Metric Value
dl 0
loc 33
rs 8.8571
c 1
b 1
f 0
cc 1
nc 2
nop 0
1
/*
2
 * Circles - Bring cloud-users closer together.
3
 *
4
 * This file is licensed under the Affero General Public License version 3 or
5
 * later. See the COPYING file.
6
 *
7
 * @author Maxence Lange <[email protected]>
8
 * @copyright 2017
9
 * @license GNU AGPL version 3 or any later version
10
 *
11
 * This program is free software: you can redistribute it and/or modify
12
 * it under the terms of the GNU Affero General Public License as
13
 * published by the Free Software Foundation, either version 3 of the
14
 * License, or (at your option) any later version.
15
 *
16
 * This program is distributed in the hope that it will be useful,
17
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19
 * GNU Affero General Public License for more details.
20
 *
21
 * You should have received a copy of the GNU Affero General Public License
22
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
23
 *
24
 */
25
26
/** global: OC */
27
/** global: OCA */
28
29
(function () {
30
31
32
	/**
33
	 * @constructs Circles
34
	 */
35
	var Circles = function () {
36
37
		$.extend(Circles.prototype, circles);
0 ignored issues
show
Bug introduced by
The variable circles seems to be never declared. If this is a global, consider adding a /** global: circles */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
38
		$.extend(Circles.prototype, members);
0 ignored issues
show
Bug introduced by
The variable members seems to be never declared. If this is a global, consider adding a /** global: members */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
39
		$.extend(Circles.prototype, links);
0 ignored issues
show
Bug introduced by
The variable links seems to be never declared. If this is a global, consider adding a /** global: links */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
40
41
		this.initialize();
42
	};
43
44
	Circles.prototype = {
45
46
47
		initialize: function () {
48
49
			var self = this;
50
51
52
			this.shareToCircle = function (circleId, source, type, item, callback) {
53
				var result = {status: -1};
54
				$.ajax({
55
					method: 'PUT',
56
					url: OC.generateUrl('/apps/circles/v1/circles/' + circleId + '/share'),
57
					data: {
58
						source: source,
59
						type: type,
60
						item: item
61
					}
62
				}).done(function (res) {
63
					self.onCallback(callback, res);
64
				}).fail(function () {
65
					self.onCallback(callback, result);
66
				});
67
			};
68
69
			this.onCallback = function (callback, result) {
70
				if (callback && (typeof callback === 'function')) {
71
					if (typeof result === 'object') {
72
						callback(result);
73
					} else {
74
						callback({status: -1});
75
					}
76
				}
77
			};
78
79
		}
80
81
	};
82
83
	OCA.Circles = Circles;
84
	OCA.Circles.api = new Circles();
85
86
})();
87
88
89